using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Specialized;
using Needle.Core.Lifetime;

namespace Needle.Simulation
{
    [Transient]
    public class Buttons : Process
    {

        Random rnd = new Random(Environment.TickCount);

        protected override IEnumerable<Task> ProcessDefinition()
        {
            int people = 10;
            while (--people > 0)
            {
                yield return Delay(TimeSpan.FromSeconds(rnd.Next(20, 60)));
                this[rnd.Next(0, 32)] = true;
                yield return RaiseEvent("ButtonPressed");
            }
        }

        private bool[] buttonStates = new bool[32];

        public bool this[int button]
        {
            get
            {
                return buttonStates[button];
            }
            set
            {
                if (buttonStates[button] != value)
                {
                    buttonStates[button] = value;
                    if (value)
                        Log("Button {0} pressed.", button);
                }
            }
        }

    }
}
